Skip to content

feat(admin): implement advanced filtering for audit logs(#248)#263

Merged
johanbriger merged 5 commits into
mainfrom
248-aktivitetslogg---lägg-till-filter-användare-klinik-ärende-senaste-uppdateringar
Apr 23, 2026

Hidden character warning

The head ref may contain hidden characters: "248-aktivitetslogg---l\u00e4gg-till-filter-anv\u00e4ndare-klinik-\u00e4rende-senaste-uppdateringar"
Merged

feat(admin): implement advanced filtering for audit logs(#248)#263
johanbriger merged 5 commits into
mainfrom
248-aktivitetslogg---lägg-till-filter-användare-klinik-ärende-senaste-uppdateringar

Conversation

@johanbriger

@johanbriger johanbriger commented Apr 23, 2026

Copy link
Copy Markdown
Contributor
  • Added search functionality for descriptions, usernames, clinic names, and record IDs.
  • Implemented filters for user roles (Vet, Admin, Pet Owner).
  • Added filtering by activity type and specific clinic.
  • Enabled date-based filtering for logs.
  • Updated ActivityLogResponse DTO to include clinicName and performedByRole.
  • Optimized backend queries using JOIN FETCH to prevent N+1 performance issues.

closes #248

Summary by CodeRabbit

New Features

  • Added comprehensive filtering for audit logs: search, action type, user role, clinic, and date options
  • Enhanced audit log display with additional metadata including role tags, patient and clinic information, and record references
  • Improved empty state messaging for filtered results

@coderabbitai

coderabbitai Bot commented Apr 23, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@johanbriger has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 18 minutes and 51 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 18 minutes and 51 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2a1db0ab-27cb-4ea1-a98d-3e243e6a7979

📥 Commits

Reviewing files that changed from the base of the PR and between 63e4614 and 377b51b.

📒 Files selected for processing (2)
  • frontend/src/components/admin/AuditLogView.jsx
  • src/main/java/org/example/vet1177/dto/response/activitylog/ActivityLogResponse.java
📝 Walkthrough

Walkthrough

The changes add filtering functionality to the activity log admin interface and extend the activity log response DTO with additional metadata fields. The frontend component now includes a filter panel for search, action type, user role, clinic, and date filtering, while the backend DTO is enriched with performer role, clinic name, and pet name fields.

Changes

Cohort / File(s) Summary
Frontend Audit Log Component
frontend/src/components/admin/AuditLogView.jsx
Added React state hooks for filtering (search, action type, user role, clinic, date); derives available clinic options from logs; computes memoized filtered results. UI restructured from unconditional timeline to filter panel plus filtered list. Log row metadata expanded with role tags, patient/clinic/record reference chips, and timestamps with seconds. Empty-state messaging updated.
Backend Activity Log DTO
src/main/java/org/example/vet1177/dto/response/activitylog/ActivityLogResponse.java
Added three new record fields: performedByRole, clinicName, and petName. Updated from() factory method to populate these fields from ActivityLog relationships with null-safe handling for missing pet data.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • PR #34: Foundational PR that introduces the ActivityLogResponse DTO structure that this PR extends with additional fields.
  • PR #66: Related PR that also extends ActivityLogResponse with the same performedByRole, clinicName, and petName fields and their factory method mappings.

Suggested reviewers

  • lindaeskilsson
  • annikaholmqvist94

Poem

🐰 A filter appears in the logs divine,
Roles, clinics, and pets all align,
With search and with date,
The activity looks great,
Now admins can filter just fine! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: implementing advanced filtering for audit logs, which is the core objective of the PR.
Linked Issues check ✅ Passed The PR implements all key requirements from issue #248: search functionality for descriptions/usernames/clinic names/record IDs, filters for user roles, activity type, clinic, and date-based filtering.
Out of Scope Changes check ✅ Passed All changes directly support the filtering feature: AuditLogView adds filter state and UI, ActivityLogResponse includes additional fields needed for filtering and display.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 248-aktivitetslogg---lägg-till-filter-användare-klinik-ärende-senaste-uppdateringar

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
frontend/src/components/admin/AuditLogView.jsx (1)

38-46: Minor: inconsistent casing on recordId search.

All other fields search against searchLower, but log.recordId?.includes(searchTerm) uses the raw term. UUIDs are lowercase but users may paste mixed case. Also, when searchTerm is empty, includes("") is trivially true — currently fine because other branches also pass on empty, but still worth normalizing for clarity.

-                log.recordId?.includes(searchTerm);
+                log.recordId?.toLowerCase().includes(searchLower);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/components/admin/AuditLogView.jsx` around lines 38 - 46, In the
useMemo that builds filteredLogs, normalize the recordId comparison the same way
as the other fields: compute searchLower and compare using
log.recordId?.toLowerCase().includes(searchLower) (keeping the existing optional
chaining), so mixed-case UUIDs match and the behavior is consistent/clear when
searchTerm is empty; update the recordId check in the filteredLogs predicate
accordingly.
src/main/java/org/example/vet1177/dto/response/activitylog/ActivityLogResponse.java (1)

33-33: Avoid hardcoded localized strings in DTO layer.

Embedding the Swedish fallback "Okänt djur" inside the DTO mixes i18n concerns into the data layer. Prefer returning null (or an empty string) here and letting the frontend render the localized fallback (the UI at AuditLogView.jsx already uses a similar pattern for clinicName || 'System'). This keeps the API locale-agnostic for future clients/translations.

♻️ Proposed change
-                log.getMedicalRecord().getPet() != null ? log.getMedicalRecord().getPet().getName() : "Okänt djur",
+                log.getMedicalRecord().getPet() != null ? log.getMedicalRecord().getPet().getName() : null,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/example/vet1177/dto/response/activitylog/ActivityLogResponse.java`
at line 33, The DTO currently embeds a Swedish fallback string ("Okänt djur")
when building ActivityLogResponse, which mixes i18n into the data layer; modify
the construction in ActivityLogResponse (the expression using
log.getMedicalRecord().getPet().getName()) to return null (or an empty string)
instead of the hardcoded "Okänt djur" so the API remains locale-agnostic and the
frontend (AuditLogView.jsx) can render a localized fallback like it already does
for clinicName.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@frontend/src/components/admin/AuditLogView.jsx`:
- Around line 163-169: The span rendering in AuditLogView.jsx incorrectly treats
ROLE_OWNER as the default slate style and can throw when performedByRole is
null; update the conditional on log.performedByRole to add an explicit branch
for 'ROLE_OWNER' (e.g., use a green owner chip class like bg-green-50
text-green-600 border-green-100) and change the text expression to use optional
chaining and a safe fallback (e.g., log.performedByRole?.replace('ROLE_', '') ??
'UNKNOWN') so the UI won't crash on null values.
- Around line 99-103: The role filter options in AuditLogView.jsx are using
short values ("VET","OWNER","ADMIN") that never match backend values like
"ROLE_VET"/"ROLE_ADMIN" (seen on log.performedByRole), so update the <option>
value attributes to the backend form (e.g.,
"ROLE_VET","ROLE_OWNER","ROLE_ADMIN") and keep the "ALL" value as-is;
alternatively, change the filtering predicate (where roleFilter is used, e.g.,
log.performedByRole === roleFilter) to normalize/compare by suffix or accept
both forms (strip the "ROLE_" prefix from log.performedByRole or prepend "ROLE_"
to roleFilter) so the comparison can succeed.
- Line 51: The date filter check in AuditLogView.jsx uses
log.createdAt.startsWith(dateFilter) which can throw if createdAt is
null/undefined; update the matchesDate assignment (the const matchesDate line)
to guard with optional chaining or a null check (e.g., use
log.createdAt?.startsWith(dateFilter) or (log.createdAt &&
log.createdAt.startsWith(dateFilter))) so the filter safely handles missing
createdAt values.

---

Nitpick comments:
In `@frontend/src/components/admin/AuditLogView.jsx`:
- Around line 38-46: In the useMemo that builds filteredLogs, normalize the
recordId comparison the same way as the other fields: compute searchLower and
compare using log.recordId?.toLowerCase().includes(searchLower) (keeping the
existing optional chaining), so mixed-case UUIDs match and the behavior is
consistent/clear when searchTerm is empty; update the recordId check in the
filteredLogs predicate accordingly.

In
`@src/main/java/org/example/vet1177/dto/response/activitylog/ActivityLogResponse.java`:
- Line 33: The DTO currently embeds a Swedish fallback string ("Okänt djur")
when building ActivityLogResponse, which mixes i18n into the data layer; modify
the construction in ActivityLogResponse (the expression using
log.getMedicalRecord().getPet().getName()) to return null (or an empty string)
instead of the hardcoded "Okänt djur" so the API remains locale-agnostic and the
frontend (AuditLogView.jsx) can render a localized fallback like it already does
for clinicName.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2a884611-07a2-40f5-b8b1-2b3b474fa0be

📥 Commits

Reviewing files that changed from the base of the PR and between 0c69c49 and 63e4614.

📒 Files selected for processing (2)
  • frontend/src/components/admin/AuditLogView.jsx
  • src/main/java/org/example/vet1177/dto/response/activitylog/ActivityLogResponse.java

Comment thread frontend/src/components/admin/AuditLogView.jsx Outdated
Comment thread frontend/src/components/admin/AuditLogView.jsx
Comment thread frontend/src/components/admin/AuditLogView.jsx Outdated
@johanbriger
johanbriger merged commit 1fb48f8 into main Apr 23, 2026
2 checks passed
@johanbriger
johanbriger deleted the 248-aktivitetslogg---lägg-till-filter-användare-klinik-ärende-senaste-uppdateringar branch April 23, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Aktivitetslogg - lägg till filter (användare, klinik, ärende, senaste uppdateringar)

1 participant